#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class SubscriptionNode : public rclcpp::Node
{
public:
    SubscriptionNode(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "Hello! I am %s", name.c_str());

        cmd_sub_ = this->create_subscription<std_msgs::msg::String>(
            "command",
            10,
            std::bind(
                &SubscriptionNode::subcription_callback, 
                this,
                std::placeholders::_1)
        );
    }

private:
    rclcpp::Subscription<std_msgs::msg::String>::SharedPtr cmd_sub_;

    void subcription_callback(const std_msgs::msg::String::SharedPtr msg)
    {
        RCLCPP_INFO(this->get_logger(), "Receive: %s", msg->data.c_str());
    }
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<SubscriptionNode>("Subscription_Node");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
1

